<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/css/profile.css"/>
<div class="main-container">
    <div class="xiu-dialog" id="bd-password">
        <div class="divColorbox_Header" class="xiu-dialog-head">
            <span><i class="fa fa-star"></i><span>修改密码</span></span>
            <a class="Refresh"></a><a class="Close"></a>
        </div>
        <p class="valid-tip"></p>
        <div class="xiu-dialog-body">
            <div class="form-group">
                <label for="" class="form-label">
                    旧密码：
                </label>
                <div class="form-hozinput">
                    <input type="password" name="pwds" class="form-control" placeholder="请输入旧密码"/>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    新密码：
                </label>
                <div class="form-hozinput">
                    <input type="password" name="newpwds" class="form-control" placeholder="请输入新密码"/>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    确认密码：
                </label>
                <div class="form-hozinput">
                    <input type="password" name="twonewpwds" class="form-control" placeholder="请再次输入新密码"/>
                </div>
            </div>

            <div class="form-group">
                <div class="form-hozinput form-hozinput-ml">
                    <input type="button" name="" class="form-button" value="提交" id="J_pwds_sub"/>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        if (!_StateData.IsLogin) {
            $.CommonMain.Modal_Tip('请先登录', {Timeout: 1000});
            location.href = '/';
        }
        $("#bd-password").show();
        $('#J_pwds_sub').on('click', function () {
            var params = {};
            params.OriginalPwd = $.trim($('input[name="pwds"]').val());
            params.Password = $.trim($('input[name="newpwds"]').val());
            params.PasswordTwo = $.trim($('input[name="twonewpwds"]').val());
            if (!params.OriginalPwd) {
                $.CommonMain.Modal_Tip('请输入旧密码', {Timeout: 2000});
                $('input[name="pwd"]').focus();
                return false;
            }
            if (!params.Password) {
                $.CommonMain.Modal_Tip('请输入新密码', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            if (!params.PasswordTwo) {
                $.CommonMain.Modal_Tip('请输入第二次新密码', {Timeout: 2000});
                $('input[name="twonewpwds"]').focus();
                return false;
            }
            if (params.PasswordTwo != params.Password) {
                $.CommonMain.Modal_Tip('你输入的两次密码不一致，请重新输入', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            if (params.Password.length < 4 || params.Password.length > 12) {
                $.CommonMain.Modal_Tip('请输入4～12字符密码', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            $.KOC.Loading.Open();
            $.ajax({
                url: '/ajax/business.user-passwordupdate',
                type: 'post',
                dataType: 'json',
                data: {
                    Password: md5(params.Password),
                    Password_Old: md5(params.OriginalPwd)
                },
                success: function (data) {
                    $.KOC.Loading.Close();
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip(data.msg + "(" + data.flag + ")", {Timeout: 2000});
                        return;
                    }
                    $.CommonMain.Modal_Tip('密码修改成功', {
                        Timeout: 3000,
                        onClose: function () {
                            $.CommonMain.Logout(1);

                        }
                    });
                }
            });
        });
    })
</script>